var ns, toast, actionsheet, UIAlbumBrowser;
var app = new Vue({
    el: '#app',
    data: {
        ID:0,
        SaleActivityInfo:{
            ProjectNameList:'',
        },
        ProductList:[],
    },
    methods: {
        get_data:function(){
            var that=this;
            that.List=[];
            var option={};
            option.ID=that.ID;
            option.action='getsaleactivityinfo';
            ns.post(option, function(succeed, data, err) {
                if(succeed){
                    console.log(JSON.stringify(data));
                    that.SaleActivityInfo=data.SaleActivityInfo;
                    that.SaleActivityInfo.ProjectNameList=(data.SaleActivityInfo.ProjectNameList).toString();
                    that.ProductList=data.ProductList;
                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    }); 
                }
                
            });


        },
        //商品详情
        do_opendetail:function(id){
            var that=this;
            ns.openWin('product_detail', '商品详情',{
                id:id,
            });
            
        },
        //结束活动
        do_saveProduct:function(){
            var that=this;
            var option={};
            option.ID=that.ID;
            option.action='stopsaleactivity';
            ns.post(option, function(succeed, data, err) {
                if(succeed){
                    if(data.status){
                        api.toast({
                            msg: "已结束",
                            duration: 2000,
                            location: 'bottom'
                        }); 
                        api.sendEvent({
                            name:'load_active'
                        });
                        that.get_data();
                    }
                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });  
                }
            });

        },
        //编辑
        do_editorder:function(){
            var that=this;
            ns.openWin('activity_add', '编辑营销活动',{
                id:that.ID,
                SaleActivityInfo:that.SaleActivityInfo,
                ProductList:that.ProductList
            });
        },
        //删除
        do_removeorder:function(){
            var that=this;
            var option={};
            option.ID=that.ID;
            option.action='removesaleactivity';
            ns.post(option, function(succeed, data, err) {
                if(succeed){
                    api.toast({
                        msg: "删除成功",
                        duration: 2000,
                        location: 'bottom'
                    }); 
                    api.sendEvent({
                        name:'load_active'
                    })
                    setTimeout(() => {
                        api.closeWin();
                    }, 500);
                    

                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });  
                }
            });
        },

    }
      
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    UIAlbumBrowser = api.require('UIAlbumBrowser');
    app.ID = api.pageParam.id;
    app.get_data();
    api.addEventListener({
        name: 'load_active'
    }, function(ret, err) {
        app.get_data();
    });

};
